home *** CD-ROM | disk | FTP | other *** search
/ Freelog 46 / Freelog046.iso / Alu / Celestia / Win32LoresTex / celestia-lores-win32-1.3.0.exe / {app} / shaders / ringshadow_arb.vp < prev    next >
Text File  |  2003-02-18  |  2KB  |  57 lines

  1. !!ARBvp1.0
  2.  
  3. # Vertex program used for applying ring shadow textures.  Ray cast from a
  4. # point on the object in the direction of the sun (assumed to be an
  5. # infinitely distant light source here.)  Compute the intersection of
  6. # the ray with the ring plane.  Then use the distance of the intersection
  7. # point from the planet's center to compute a texture coordinate.  Vertex
  8. # programs are cool!
  9.  
  10. ATTRIB iPos          = vertex.position;
  11. PARAM  mvp[4]        = { state.matrix.mvp };
  12. PARAM  lightDir      = program.env[0];
  13. PARAM  diffuse       = program.env[2];
  14. PARAM  ringSize      = program.env[10];
  15. PARAM  rcpSunY       = program.env[11];
  16. PARAM  zero          = 0;
  17. PARAM  half          = 0.5;
  18. OUTPUT oPos          = result.position;
  19. OUTPUT oColor        = result.color;
  20. OUTPUT oTex0         = result.texcoord[0];
  21.  
  22. TEMP   s;
  23.  
  24. # Transform the vertex by the modelview matrix
  25. DP4   oPos.x, mvp[0], iPos;
  26. DP4   oPos.y, mvp[1], iPos;
  27. DP4   oPos.z, mvp[2], iPos;
  28. DP4   oPos.w, mvp[3], iPos;
  29.  
  30. # Scale by oblateness . . . off for now because it makes Saturn look
  31. # weird, even though I think it's more realistic.
  32. # MUL   p, iPos, scale;
  33.  
  34. MUL   s.x, iPos.y, -rcpSunY.x;
  35. MAX   s.x, s.x, zero;        # Clamp to zero--don't trace both directions
  36. MAD   s, s.x, lightDir, iPos;
  37.  
  38. # Compute the distance from the center.  The s coordinate is the distance
  39. # from the center, modified by the ring width and inner radius
  40. DP3   s.x, s, s;
  41. RSQ   s.x, s.x;
  42. RCP   s.x, s.x;
  43.  
  44. # Scale and bias by ring width and radius
  45. MUL   s.x, s.x, ringSize.y;
  46. ADD   s.x, s.x, -ringSize.x;
  47.  
  48. # Now we have our s coordinate . . .
  49. MOV   oTex0.x, s.x;
  50. # The t coordinate is always 0.5
  51. MOV   oTex0.y, half;
  52.  
  53. MOV   oColor, diffuse;
  54.  
  55. END
  56.  
  57.